# -*- coding: utf-8 -*-

import sys
from PySide.QtCore import *
from PySide.QtGui import *
from form import Ui_Form
 
class MainUi(QWidget,Ui_Form):
    def __init__(self,parent = None):
        super(MainUi,self).__init__(parent)     
        self.setupUi(self)
        self.startBtn.setEnabled(True)
        self.stopBtn.setEnabled(False)
        
        self.timer=QTimer()
        self.second=0
        self._connect_slot()
        
    def _connect_slot(self):
        self.startBtn.clicked.connect(self.count_start)#同步textEdit和textBrowser的内容
        self.stopBtn.clicked.connect(self.count_stop)#退出按钮
        self.timer.timeout.connect(self.update_time_label)
         
    def update_time_label(self):
        self.second=self.second+1
        text = "%d : %d" %(self.second//60,self.second%60)
        self.timeLabel.setText(text)
        self.progressBar.setValue(self.second)
        
    def count_start(self):
        self.second=0
        self.timer.start(1000)
        self.startBtn.setEnabled(False)
        self.stopBtn.setEnabled(True)
        
    def count_stop(self):
        self.second=0
        self.timer.stop()
        self.timeLabel.setText(":")
        self.startBtn.setEnabled(True)
        self.stopBtn.setEnabled(False)
        
def main():
    app = QApplication(sys.argv)
    ui = MainUi()
    ui.show()
    sys.exit(app.exec_())
 
if __name__ == '__main__':
    main()